import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./assets/index.css";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";

Vue.use(ElementUI);
Vue.config.productionTip = false;
import apis from "./scripts/apis.js";
Vue.prototype.$apis = apis;

// 全局路由守卫
router.beforeEach((to, from, next) => {
  // console.log(to)
  if (to.name !== "login" && !sessionStorage.getItem("token")) {
    next("/login");
  } else if (to.name === "login" && sessionStorage.getItem("token")) {
    next("/index");
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
